import $ from 'jquery'

import '../style/style.scss'

import collapse from '../view/Collapse/index'
const parser = require('@babel/parser');
const traverse = require("@babel/traverse");
const generator = require("@babel/generator");
import template from "babel-template";
import * as t from "babel-types";
;( ($) => {

    const $app = $('#root'),
            $container = $('<div class="container pt-6">');
    
    const fold = collapse();

    function init() {
        render();
        bindEvent();
        testxx()
    }
    function testxx() {
        // 源代码
        const code = `
        function funA() {
            console.log(1)
            const aa = 24;
            console.log('嗨了', 909)
        }
        `;
        const ast = parser.parse(code);
        const visitor = {
            CallExpression(path) {
                const callee = path.node.callee;
                if ( t.isMemberExpression(callee) ) {
                    const { object, property } = callee;
                    if ( t.isIdentifier(object,{name:'console'}) && t.isIdentifier(property,{ name:'log'})) {
                        // const parent = path.getFunctionParent();
                        // const parentFunName = parent.node.id.name;
                        // path.node.arguments.unshift(t.stringLiteral(`from function ${parentFunName}`));
                        path.remove();
                    }
                }
            }
        }
        traverse.default(ast, visitor);
        // 3. 生成
        const result = generator.default(ast, {}, code);

        console.log(result)
    }

    function render() {
        $container.append( fold.tpl() );
        $app.append( $container );
    }
    function bindEvent() {
        fold.bindEvent();
    }

    init();

})($)